<?php
class handle_paging
{	
	public function paging_display($total, $current, $perPage, $url = '', $lang, $stypelink='/',$typefile='.html')
	{	
        $numPage = ceil($total/ $perPage);
        $current= $current==''?1:$current;
		$strPagingHtml = '<ul>';
        if ($total=="" || $numPage == 1) return $strPagingHtml;
        
		if ($current!="" && $current > 1)
			$strPagingHtml .= '<li><a href="'.$url.$stypelink.'1'.$typefile.'" >'.$lang['Start'].'</a></li><li><a href="'.$url.$stypelink.($current - 1).''.$typefile.'" >'.$lang['Back'].'</a></li>';
        else $strPagingHtml .= '<li class="previous-off"><a class="disable" href="#">'.$lang['Start'].'</a></li><li class="previous-off"><a class="disable" href="#">'.$lang['Back'].'</a></li>'; 
		
        if($current <=3){
			for($i=1; ($i<=5) and ($i <= $numPage); $i++)
				if ($i == $current) $strPagingHtml .= '<li class="active"><a class="disable" href="#">'.$i.'</a></li>';
				else $strPagingHtml .= '<li><a  href="'.$url.$stypelink.$i.''.$typefile.'">'.$i.'</a></li>';
			
        } else {
			if ($numPage >= $current + 2)
				for($i=$current-2; ($i <=$current+2) and ($i <= $numPage); $i++)
					if ($i == $current) $strPagingHtml .= '<li class="active"><a class="disable" href="#">'.$i.'</a></li>';
					else $strPagingHtml .= '<li><a href="'.$url.$stypelink.$i.''.$typefile.'">'.$i.'</a></li>';
				
			else
				for($i = $numPage - 4;$i <= $numPage; $i++)
					if($i > 0)
						if ($i == $current) $strPagingHtml .= '<li class="active"><a class="disable" href="#">'.$i.'</a></li>';
						else $strPagingHtml .= '<li><a href="'.$url.$stypelink.$i.''.$typefile.'">'.$i.'</a></li>';
        }
        
		if ($current < $numPage)
			 $strPagingHtml .= '<li><a href="'.$url.$stypelink.($current + 1).''.$typefile.'">'.$lang['Next'].'</a></li><li><a href="'.$url.$stypelink.$numPage.''.$typefile.'">'.$lang['End'].'</a></li>';
        else $strPagingHtml .= '<li class="previous-off"><a class="disable" href="#">'.$lang['Next'].'</a></li><li class="previous-off"><a class="disable" href="#">'.$lang['End'].'</a></li>';  
		
		$strPagingHtml .='</ul><div style="clear:both;height: 0px;">&nbsp;</div>';
		return $strPagingHtml;
    }
	
	
}

?>